package com.example.zqm.git72.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.zqm.git72.Adapter.SearchActivityAdapter;
import com.example.zqm.git72.JavaBean.Activity;
import com.example.zqm.git72.JavaBean.Master;
import com.example.zqm.git72.Model.ActivityModel;
import com.example.zqm.git72.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchAcitivityActivity extends AppCompatActivity {
    private ImageView send1;
    private  EditText in1;
    private  RecyclerView recyclerView;
    String name;
    List<Activity> activities;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_searchactivity);
        recyclerView = (RecyclerView)findViewById(R.id.searching1);
        recyclerView.setLayoutManager(new LinearLayoutManager(SearchAcitivityActivity.this));
        initView();
        initGG();
    }
    public  void  initView(){
        send1=(ImageView)findViewById(R.id.send1);
        in1=(EditText)findViewById(R.id.in1);
    }
    public  void initGG(){
        send1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name =in1.getText().toString();
                ActivityModel activityModel = new ActivityModel();
                Call<List<Activity>> call =activityModel.bysearch(name);
                call.enqueue(new Callback<List<Activity>>() {
                    @Override
                    public void onResponse(Call<List<Activity>> call, Response<List<Activity>> response) {
                        activities =response.body();
                        recyclerView.setAdapter(new SearchActivityAdapter(SearchAcitivityActivity.this, activities));
                    }

                    @Override
                    public void onFailure(Call<List<Activity>> call, Throwable t) {

                    }
                });
            }
        });
    }
}
